<!-- 短信触达率 -->
<template>
	<div id="SmsQuality">
		<a-card :bordered="false">
			<a-form ref="searchFormRef" name="advanced_search" :model="searchFormState" class="ant-advanced-search-form">
				<a-row :gutter="24">
					<a-col :span="6">
						<a-form-item label="所属项目" name="projectCode">
							<ProjectSelect v-model:value="searchFormState.projectCode" />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-form-item label="时间范围" name="dateRange">
							<a-range-picker v-model:value="searchFormState.dateRange" valueFormat="YYYY-MM-DD" :allowClear="false" />
						</a-form-item>
					</a-col>
					<a-col :span="6">
						<a-button type="primary" @click="tableRef.refresh(true)">查询</a-button>
						<a-button style="margin: 0 8px" @click="reset">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</a-card>
		<a-card :bordered="false" class="mt-2">
			<s-table ref="tableRef" :columns="columns" :data="loadData" bordered :tool-config="toolConfig">
				<!-- <template #bodyCell="{ column, record }">
					<template v-if="column.dataIndex === 'timeRange'">
						<span>2025-6-25</span>
					</template>
				</template> -->
			</s-table>
		</a-card>
	</div>
</template>
<script setup name="SmsQuality">
	import passQualitySmsApi from '@/api/tjzy/passQuality/sms/passQualitySmsApi'
	import dayjs from 'dayjs'
	import ProjectSelect from '@/components/Tjzy/Project/index.vue'
// ===========================================DATA======================================================

const searchFormState = ref({
		projectCode: undefined,
		dateRange: [dayjs().format('YYYY-MM-DD'), dayjs().format('YYYY-MM-DD')]
	})
	const searchFormRef = ref()
	const tableRef = ref()
	const toolConfig = { refresh: true, height: true, columnSetting: false, striped: false }
	const columns = [
		{
			title: '项目名称',
			dataIndex: 'projectName'
		},
		{
			title: '时间范围',
			dataIndex: 'timeRange'
		},
		{
			title: '接通率',
			dataIndex: 'smsSendRate',
			customRender: ({ text }) => {
				return `${(text * 100).toFixed(2)}%`
			}
		}
	]
	// ===========================================WATCH=====================================================
	// ===========================================LIFECYCLE HOOKS===========================================
	// ===========================================METHODS==================================================
	const reset = () => {
		searchFormRef.value.resetFields()
		tableRef.value.refresh(true)
	}
	// ===========================================REQUEST==================================================
	const loadData = (parameter) => {
		const data = {
			projectCode: searchFormState.value.projectCode,
			beginTime: `${searchFormState.value.dateRange[0]} 00:00:00`,
			endTime: `${searchFormState.value.dateRange[1]} 23:59:59`
		}
		return passQualitySmsApi.pageList(data).then((res) => {
			if (res && res.records && res.records.length > 0) {
				res.records.forEach((item) => {
					item.timeRange = `${searchFormState.value.dateRange[0]} 至 ${searchFormState.value.dateRange[1]}`
				})
			}
			return res
		})
	}
</script>
<style lang="less" scoped></style>
